package main.java;

import main.java.algorithms.Dijkstra;
import main.java.data_structure.SparseWeightedGraph;
import main.java.utils.ReadWeightedGraph;

/**
 * @author Wrb
 * @date 2019/6/18 10:39
 */
public class DijkstraMain {
	// 测试我们的Dijkstra最短路径算法
	public static void main(String[] args) {

		String filename = "testG1Dijkstra.txt";
		int V = 5;

		SparseWeightedGraph<Integer> g = new SparseWeightedGraph<Integer>(V, true);
		// Dijkstra最短路径算法同样适用于有向图
		//SparseGraph<int> g = SparseGraph<int>(V, false);
		ReadWeightedGraph readGraph = new ReadWeightedGraph(g, filename);

		System.out.println("Test Dijkstra:\n");
		Dijkstra<Integer> dij = new Dijkstra<Integer>(g,0);
		for( int i = 1 ; i < V ; i ++ ){
			if(dij.hasPathTo(i)) {
				System.out.println("Shortest Path to " + i + " : " + dij.shortestPathTo(i));
				dij.showPath(i);
			}
			else
				System.out.println("No Path to " + i );

			System.out.println("----------");
		}

	}
}
